package com.lzx.blog.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lzx.blog.entity.User;
import com.lzx.blog.service.UserService;
import com.lzx.blog.utils.R;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author 程序员星星
 * @date 2023/4/12
 * @Description
 */
@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("/login")
    public R login(@RequestBody User user) {
        User dbUser = userService.getOne(Wrappers.<User>lambdaQuery()
                .eq(User::getUsername, user.getUsername())
                .eq(User::getPassword, user.getPassword()));
        if (dbUser != null) {
            return R.ok().data("user", dbUser).message("登录成功！");
        } else {
            return R.error().message("用户名或密码错误，请重试！");
        }
    }
}
